# coding:UTF-8
# ________________________
# Project_Name:pythonProject
# File_Name:Administrator
# Author:Administrator
# Date_Time:2022/4/22 9:53
# Description:
# ________________________
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


def  foo1():
    driver = webdriver.Chrome()

    driver.maximize_window()

    driver.get(r"C:\PycharmProjects\pythonProject\pyzidonghua\selenium_3\example.html")
    time.sleep(2)

    #找到下拉菜单元素
    sel=driver.find_element(By.ID,"Selector")
    # #构造下拉菜单的对象
    select=Select(sel)
    #根据option的value属性选择
    select.select_by_value("peach")
    time.sleep(2)
    #根据option的text选择
    select.select_by_visible_text("3.香蕉")
    time.sleep(2)
    #根据option索引值d选择:从0开始
    select.select_by_index(3)
    time.sleep(2)


    driver.quit()

if  __name__=="__main__":
    foo1()